<script>
  //  import AppList from './dlg-list.vue'
  import * as utils from '../utils/index'
  import { Form, Alert } from 'element-ui'
  //  import * as test from './test'
  //  import FormField from  './forms/index'
  //  import { select } from './forms/index'
  export default {
    name: 'ElTest',
    componentName: 'ElTest',
    props: ['options'],
    methods: {
      makeItemProps(item) {
        return {
          props: {
            label: item.label
          }
        }
      },
      makeParam(item, result = {}, self) {
        item.value = item.value || ''
        item.key = item.key || item.value
//        result[item.key] = result[item.key] || item.value
        let props = {result}
        if (!item.componentName || (item.componentName).indexOf('el-') > -1) {
          Object.assign(props, item)
        } else {
          props.options = item
        }
        return {
          domProps: {
            value: self.formData[item.key] || ''
          },
          props: {
            ...props,
            value: self.formData[item.key] || ''
          },
          on: {
            input: (val) => {
              self.formData[item.key] = val
//              self.$emit('input', val)
              console.log('this', self.formData, val)
            }
          }
        }
      }
    },
    mounted () {
      const result = {}
      this.options.forEach(item => {
        result[item.key] = result[item.key] || item.value
      })
      this.$set(this, 'formData', {})
      this.formData = Object.assign({}, this.formData, result)
    },
    data () {
      return {
        formData: {},
        value: 'true',
        resultMap: null
      }
    },
    render(h) {
      const {makeItemProps, makeParam} = this
//      this.$set(this, 'formData', {})
      const self = this
//      const inputProps = {
//        props: {
//          value: JSON.stringify(self.formData)
//        }
//      }
      return (
        <el-form label-width="80px">
          <el-card>
            {(this.options.map(item => {
              return (
                <el-form-item {...makeItemProps(item) }>
                  {
                    h(item.componentName, makeParam(item, this.formData, self), item.render && item.render(h, item))
                  }
                </el-form-item>
              )
            }))
            }
          </el-card>
        </el-form>
      )
    }
  }
</script>
